/*
 * UserDTO.java.
 */
package com.phonemap.dto;

import java.io.Serializable;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;

import javax.servlet.http.HttpServletRequest;

import org.json.JSONObject;

import com.google.appengine.api.datastore.GeoPt;

/**
 * The Class UserDTO.
 */
public class UserDTO implements Serializable {

	/** The Constant serialVersionUID. */
	private static final long serialVersionUID = 1L;

	/** The user id. */
	private long userId;

	/** The fullname. */
	private String fullname;

	/** The link. */
	private String link;

	/** The birthday. */
	private Date birthday;

	/** The interested in. */
	private String interestedIn;

	/** The gender. */
	private String gender;

	/** The email. */
	private String email;

	/** The relationship status. */
	private String relationshipStatus;

	/** The timezone. */
	private String timezone;

	/** The locale. */
	private String locale;

	/** The verified. */
	private String verified;

	/** The updated time. */
	private String updatedTime;

	/** The username. */
	private String username;

	/** The password. */
	private String password;

	/** The located. */
	private GeoPt located;

	/** The located time. */
	private Date locatedTime;

	/** The phone. */
	private String phone;

	/**
	 * Instantiates a new user dto.
	 */
	public UserDTO() {

	}

	/**
	 * Instantiates a new user dto.
	 * 
	 * @param json
	 *            the json
	 */
	public UserDTO(final JSONObject json) {
		
		try {
			this.userId = json.getLong("user_id");
			this.fullname = json.getString("fullname");
			this.link = json.getString("link");
			SimpleDateFormat formatter = new SimpleDateFormat("dd/MM/yyyy");
			try {
				if (json.getString("birthday") != null) {
					this.birthday = formatter.parse(json.getString("birthday"));
				}
			} catch (ParseException e) {
				e.printStackTrace();
			}
			this.interestedIn = json.getString("interested_in");
			this.gender = json.getString("gender");
			this.relationshipStatus = json.getString("relationship_status");
			this.timezone = json.getString("timezone");
			this.locale = json.getString("locale");
			this.verified = json.getString("verified");
			this.email = json.getString("email");
			this.updatedTime = json.getString("updated_time");
			this.username = json.getString("username");
			this.password = null;
			this.located = new GeoPt(Float.parseFloat(json.getString("lat")),
					Float.parseFloat(json.getString("lng")));
			this.phone = json.getString("phone");
		} catch (Exception e) {
			e.printStackTrace();
		}

	}
	
	/**
	 * Instantiates a new user dto.
	 * 
	 * @param req
	 *            the req
	 */
	public UserDTO(final HttpServletRequest req) {

		this.userId = Long.parseLong(req.getParameter("fid"));
		this.fullname = req.getParameter("fullname");
		this.link = req.getParameter("link");
		SimpleDateFormat formatter = new SimpleDateFormat("dd/MM/yyyy");
		try {
			if (req.getParameter("birthday") != null) {
				this.birthday = formatter.parse(req.getParameter("birthday"));
			}
		} catch (ParseException e) {
			e.printStackTrace();
		}
		this.interestedIn = req.getParameter("interested_in");
		this.gender = req.getParameter("gender");
		this.relationshipStatus = req.getParameter("relationship_status");
		this.timezone = req.getParameter("timezone");
		this.locale = req.getParameter("locale");
		this.verified = req.getParameter("verified");
		this.email = req.getParameter("email");
		this.updatedTime = req.getParameter("updated_time");
		this.username = req.getParameter("username");
		this.password = null;
		this.located = new GeoPt(Float.parseFloat(req.getParameter("lat")),
				Float.parseFloat(req.getParameter("lng")));
		this.phone = req.getParameter("phone");

	}

	/**
	 * Gets the user id.
	 * 
	 * @return the user id
	 */
	public long getUserId() {
		return this.userId;
	}

	/**
	 * Sets the user id.
	 * 
	 * @param userId
	 *            the new user id
	 */
	public void setUserId(long userId) {
		this.userId = userId;
	}

	/**
	 * Gets the fullname.
	 * 
	 * @return the fullname
	 */
	public String getFullname() {
		return this.fullname;
	}

	/**
	 * Sets the fullname.
	 * 
	 * @param fullname
	 *            the new fullname
	 */
	public void setFullname(String fullname) {
		this.fullname = fullname;
	}

	/**
	 * Gets the link.
	 * 
	 * @return the link
	 */
	public String getLink() {
		return this.link;
	}

	/**
	 * Sets the link.
	 * 
	 * @param link
	 *            the new link
	 */
	public void setLink(String link) {
		this.link = link;
	}

	/**
	 * Gets the birthday.
	 * 
	 * @return the birthday
	 */
	public Date getBirthday() {
		return this.birthday;
	}

	/**
	 * Sets the birthday.
	 * 
	 * @param birthday
	 *            the new birthday
	 */
	public void setBirthday(Date birthday) {
		this.birthday = birthday;
	}

	/**
	 * Gets the interested in.
	 * 
	 * @return the interested in
	 */
	public String getInterestedIn() {
		return this.interestedIn;
	}

	/**
	 * Sets the interested in.
	 * 
	 * @param interestedIn
	 *            the new interested in
	 */
	public void setInterestedIn(String interestedIn) {
		this.interestedIn = interestedIn;
	}

	/**
	 * Gets the gender.
	 * 
	 * @return the gender
	 */
	public String getGender() {
		return this.gender;
	}

	/**
	 * Sets the gender.
	 * 
	 * @param gender
	 *            the new gender
	 */
	public void setGender(String gender) {
		this.gender = gender;
	}

	/**
	 * Gets the email.
	 * 
	 * @return the email
	 */
	public String getEmail() {
		return this.email;
	}

	/**
	 * Sets the email.
	 * 
	 * @param email
	 *            the new email
	 */
	public void setEmail(String email) {
		this.email = email;
	}

	/**
	 * Gets the relationship status.
	 * 
	 * @return the relationship status
	 */
	public String getRelationshipStatus() {
		return this.relationshipStatus;
	}

	/**
	 * Sets the relationship status.
	 * 
	 * @param relationshipStatus
	 *            the new relationship status
	 */
	public void setRelationshipStatus(String relationshipStatus) {
		this.relationshipStatus = relationshipStatus;
	}

	/**
	 * Gets the timezone.
	 * 
	 * @return the timezone
	 */
	public String getTimezone() {
		return this.timezone;
	}

	/**
	 * Sets the timezone.
	 * 
	 * @param timezone
	 *            the new timezone
	 */
	public void setTimezone(String timezone) {
		this.timezone = timezone;
	}

	/**
	 * Gets the locale.
	 * 
	 * @return the locale
	 */
	public String getLocale() {
		return this.locale;
	}

	/**
	 * Sets the locale.
	 * 
	 * @param locale
	 *            the new locale
	 */
	public void setLocale(String locale) {
		this.locale = locale;
	}

	/**
	 * Gets the verified.
	 * 
	 * @return the verified
	 */
	public String getVerified() {
		return this.verified;
	}

	/**
	 * Sets the verified.
	 * 
	 * @param verified
	 *            the new verified
	 */
	public void setVerified(String verified) {
		this.verified = verified;
	}

	/**
	 * Gets the updated time.
	 * 
	 * @return the updated time
	 */
	public String getUpdatedTime() {
		return this.updatedTime;
	}

	/**
	 * Sets the updated time.
	 * 
	 * @param updatedTime
	 *            the new updated time
	 */
	public void setUpdatedTime(String updatedTime) {
		this.updatedTime = updatedTime;
	}

	/**
	 * Gets the username.
	 * 
	 * @return the username
	 */
	public String getUsername() {
		return this.username;
	}

	/**
	 * Sets the username.
	 * 
	 * @param username
	 *            the new username
	 */
	public void setUsername(String username) {
		this.username = username;
	}

	/**
	 * Gets the password.
	 * 
	 * @return the password
	 */
	public String getPassword() {
		return this.password;
	}

	/**
	 * Sets the password.
	 * 
	 * @param password
	 *            the new password
	 */
	public void setPassword(String password) {
		this.password = password;
	}

	/**
	 * Gets the located.
	 * 
	 * @return the located
	 */
	public GeoPt getLocated() {
		return this.located;
	}

	/**
	 * Sets the located.
	 * 
	 * @param located
	 *            the new located
	 */
	public void setLocated(GeoPt located) {
		this.located = located;
	}

	/**
	 * Gets the located time.
	 * 
	 * @return the located time
	 */
	public Date getLocatedTime() {
		return this.locatedTime;
	}

	/**
	 * Sets the located time.
	 * 
	 * @param locatedTime
	 *            the new located time
	 */
	public void setLocatedTime(Date locatedTime) {
		this.locatedTime = locatedTime;
	}

	/**
	 * Gets the phone.
	 * 
	 * @return the phone
	 */
	public String getPhone() {
		return this.phone;
	}

	/**
	 * Sets the phone.
	 * 
	 * @param phone
	 *            the new phone
	 */
	public void setPhone(String phone) {
		this.phone = phone;
	}

}
